package com.zengguang.testkaoshi.controller;

import com.zengguang.testkaoshi.pojo.Rolepersonauth;
import com.zengguang.testkaoshi.services.impl.RolePersonAuthService;
import com.zengguang.testkaoshi.tool.ResponseMessage;
import com.zengguang.testkaoshi.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "rolePersonAuth")
@RestController
@CrossOrigin
public class RolePersonAuthAction {
    @Autowired
    private RolePersonAuthService rolePersonAuthService;
    @ApiOperation(value = "权限信息查询方法")
    @RequestMapping(value = "/selectAllRolePersonAuth",method = RequestMethod.GET)
    public ResponseMessage selectRolepersonauth(Rolepersonauth rolepersonauth) {
        Map<String, List> map=new HashMap<>();
        List<Rolepersonauth> list=rolePersonAuthService.selectAllRolepersonauth();
        if (!list.isEmpty()){
            map.put("list",list);
            return Result.success("200",map);
        }
        return Result.error("查询失败");
    }

    @ApiOperation("插入角色权限信息")
    @RequestMapping(value = "/insertRolepersonauth",method = RequestMethod.GET)
    public ResponseMessage insertRolepersonauth(Rolepersonauth rolepersonauth){
        int temp=0;
        if (rolepersonauth!=null){
            if (rolepersonauth.getRolepersonauthid()!=0){
                temp=rolePersonAuthService.insertRolepersonauth(rolepersonauth);
                if (temp>0) {
                    return Result.success("插入角色权限信息成功");
                }
                else  {
                    return Result.error("该角色权限已存在");
                }
            }
        }
        return Result.error("插入角色权限信息失败");
    }

    @ApiOperation("删除角色权限信息")
    @RequestMapping(value = "/deleteRolepersonauth",method = RequestMethod.GET)
    public ResponseMessage deleteRolepersonauth(Rolepersonauth rolepersonauth){
        int temp=0;
        if (rolepersonauth!=null){
            if (rolepersonauth.getRolepersonauthid()!=0){
                temp=rolePersonAuthService.deleteRolepersonauth(rolepersonauth);
                if (temp>0) {
                    return Result.success("删除角色权限信息成功");
                }
                else {
                    return Result.error("无该角色权限");
                }
            }
        }
        return Result.error("删除角色权限信息失败");
    }

    @ApiOperation("修改角色权限信息")
    @RequestMapping(value = "/updateRolerpower",method = RequestMethod.GET)
    public ResponseMessage updateRolepersonauth(Rolepersonauth rolepersonauth){
        int temp=0;
        if (rolepersonauth!=null){
            if (rolepersonauth.getRolepersonauthid()!=0){
                temp=rolePersonAuthService.updateRolepersonauth(rolepersonauth);
                if (temp>0) {
                    return Result.success("更新角色权限信息成功");
                }
                else {
                    return Result.error("无该角色权限信息");
                }
            }
        }
        return Result.error("更新角色权限信息失败");
    }
}
